<include file="public/layout" />
<style>
    .err{color:#F00; display:none;}
</style>
<script src="__ROOT__/public/static/js/layer/laydate/laydate.js"></script>
<body style="background-color: #FFF; overflow: auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3>促销管理 - 编辑拼团</h3>
                <h5>网站系统拼团活动详情页</h5>
            </div>
        </div>
    </div>
    <form class="form-horizontal" id="handleposition" method="post" onsubmit="return false;">
        <input type="hidden" name="team_id" value="{$teamActivity.team_id}">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>拼团标题</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="act_name" value="{$teamActivity.act_name}" class="input-txt">
                    <span class="err" id="err_act_name"></span>
                    <span class="err" id="err_team_id"></span>
                    <p class="notic">请填写拼团标题</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>发放类型</label>
                </dt>
                <dd class="opt ctype">
                    <volist name="$Think.config.TEAM_TYPE" id="type">
                        <input name="team_type" class="team_type" type="radio" value="{$key}" <if condition="$teamActivity['team_type'] eq $key">checked='checked'</if>><label>{$type}</label>
                    </volist>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>选择拼团商品</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="goods_name" readonly value="{$teamActivity.goods_name}" class="input-txt">
                    <div style="overflow: hidden" id="selected_group_goods">
                        <if condition="$teamActivity['goods_id'] gt 0">
                            <input type="hidden" id="goods_id" name="goods_id" value="{$teamActivity.goods_id}">
                            <div style="float: left;margin-right: 10px" class="selected-group-goods">
                                <div class="goods-thumb"><img style="width: 162px;height: 162px"  <notempty name="$teamActivity['specGoodsPrice']">src="{$teamActivity['specGoodsPrice']['spec_img']}"<else/>src="{$teamActivity['goods_id']|goods_thum_images=162,162}"</notempty>/></div>
                                <div class="goods-name">
                                    <a  href="{:U('Home/Goods/goodsInfo',array('id'=>$teamActivity['goods_id']))}">{$teamActivity.goods_name}</a>
                                </div>
                                <div class="goods-price">
                                    <notempty name="teamActivity['specGoodsPrice']">
                                        <input type="hidden" name="item_id" value="{$teamActivity.item_id}">
                                        商城价：￥{$teamActivity['specGoodsPrice']['price']}库存:{$teamActivity['specGoodsPrice']['store_count']}
                                        <else/>
                                        商城价：￥{$teamActivity['goods']['shop_price']}库存:{$teamActivity['goods']['store_count']}
                                    </notempty>
                                </div>
                            </div>
                        </if>
                    </div>
                    <span class="err" id="err_goods_name"></span>
                    <p class="notic">
                        <a onclick="selectGoods()" class="ncap-btn" id="select_goods_button"><i class="fa fa-search"></i>选择商品</a>
                    </p>
                </dd>
            </dl>
            <dl class="row commission">
                <dt class="tit">
                    <label><em>*</em>团长佣金</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="bonus" value="{$teamActivity.bonus}"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" class="input-txt">
                    <span class="err" id="err_bonus"></span>
                    <p class="notic">拼团成功后，开团人能获得的佣金<br/>必须是0.01~1000000之间的数字(单位：元)</p>
                </dd>
            </dl>
            <dl class="row luck">
                <dt class="tit">
                    <label><em>*</em>抽奖限量</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="stock_limit" value="{$teamActivity.stock_limit}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" class="input-txt">
                    <span class="err" id="err_stock_limit"></span>
                    <p class="notic">中奖人数(单位：人)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>成团有效期</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="time_limit" value="{$teamActivity.time_limit_hours}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" class="input-txt">
                    <span class="err" id="err_goods_num"></span>
                    <p class="notic">开团后有效时间范围(单位：小时)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>拼团价格</label>
                </dt>
                <dd class="opt">
                    <input type="text"  name="team_price" value="{$teamActivity.team_price}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"  class="input-txt">
                    <span class="err" id="err_team_price"></span>
                    <p class="notic">商品拼团价格为该商品参加活动时的拼团价格<br/>必须是0.01~1000000之间的数字(单位：元)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>需要成团人数</label>
                </dt>
                <dd class="opt">
                    <input type="text"  name="needer" value="{$teamActivity.needer}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"  class="input-txt">
                    <span class="err" id="err_needer"></span>
                    <p class="notic">需要多少人拼团才能成功(单位：人)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>购买限制数</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="buy_limit" value="{$teamActivity.buy_limit}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"  class="input-txt">
                    <span class="err" id="err_buy_limit"></span>
                    <p class="notic">限制购买商品个数,0为不限制(单位：个),抽奖团限购数为1</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>虚拟销售基数</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="virtual_num" value="{$teamActivity.virtual_num}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"  class="input-txt">
                    <span class="err" id="err_virtual_num"></span>
                    <p class="notic">虚拟购买商品数(单位：个)</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>分享标题</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="share_title" value="{$teamActivity.share_title}" class="input-txt">
                    <span class="err" id="err_share_title"></span>
                    <p class="notic">请填写分享标题</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>分享描述</label>
                </dt>
                <dd class="opt">
                    <textarea placeholder="请输入分享描述" name="share_desc" rows="6" class="tarea">{$teamActivity.share_desc}</textarea>
                    <p class="notic">拼团描述介绍</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em>分享图片</label>
                </dt>
                <dd class="opt">
                    <div class="input-file-show">
                        <span class="show">
                            <a id="img_a"  class="nyroModal" rel="gal" href="{$teamActivity.share_img}">
                                <i id="img_i" class="fa fa-picture-o" onMouseOver="layer.tips('<img src={$teamActivity.share_img}>',this,{tips: [1, '#fff']});" onMouseOut="layer.closeAll();"></i>
                            </a>
                        </span>
                        <span class="type-file-box">
                            <input type="text" id="imagetext" name="share_img" value="{$teamActivity.share_img}" class="type-file-text">
                            <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                            <input class="type-file-file" onClick="GetUploadify(1,'share_img','activity','img_call_back')" size="30" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
                        </span>
                    </div>
                    <span class="err" id="err_share_img"></span>
                    <p class="notic">请上传图片格式文件</p>
                </dd>
            </dl>
            <div class="bot"><a onclick="verifyForm()" class="ncap-btn-big ncap-btn-green">确认提交</a></div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $(document).on("click", '#submit', function (e) {
            $('#submit').attr('disabled',true);
            verifyForm();
        })
    })
    $(document).ready(function(){
        initType();
    });
    $(function () {
        $(document).on("click", ".team_type", function (e) {
            initType();
        })
    })
    function initType(){
        var type = $("input[name='team_type']:checked").val();
        var commission = $('.commission');
        var luck = $('.luck');
        switch(parseInt(type))
        {
            case 0:
                commission.hide();
                luck.hide();
                break;
            case 1:
                commission.show();
                luck.hide();
                break;
            case 2:
                commission.hide();
                $("input[name='buy_limit']").val(1);
                luck.show();
                break;
            default:
                commission.hide();
                luck.hide();
        }
    }
    function verifyForm(){
        $('span.err').hide();
        $.ajax({
            type: "POST",
            url: "{:U('Team/save')}",
            data: $('#handleposition').serialize(),
            dataType: "json",
            error: function () {
                layer.alert("服务器繁忙, 请联系管理员!");
            },
            success: function (data) {
                if (data.status == 1) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    }, function(){
                        location.href = "{:U('Team/index')}";
                    });
                } else {
                    layer.msg(data.msg, {icon: 2,time: 1000});
                    $.each(data.result, function (index, item) {
                        $('#err_' + index).text(item).show();
                    });
                }
            }
        });
    }
    function selectGoods(){
        var url = "{:U('Promotion/search_goods',array('tpl'=>'select_goods','prom_type'=>6))}";
        layer.open({
            type: 2,
            title: '选择商品',
            shadeClose: true,
            shade: 0.2,
            area: ['75%', '75%'],
            content: url,
        });
    }
    function call_back(goodsItem){
        $('#goods_id').val(goodsItem.goods_id);
        var html = '';
        if(goodsItem.spec != null){
            //有规格
            html = '<input type="hidden" id="goods_id" name="goods_id" value="'+goodsItem.goods_id+'">' +
                    '<input type="hidden" id="goods_name" name="goods_name" value="'+goodsItem.goods_name+goodsItem.spec.key_name+'">' +
                    '<input type="hidden" name="item_id" value="'+goodsItem.spec.item_id+'">' +
                    '<div style="float: left;margin: 10px auto;" class="selected-group-goods"><div class="goods-thumb">' +
                    '<img style="width: 162px;height: 162px" src="'+goodsItem.spec.spec_img+'"/></div> <div class="goods-name"> ' +
                    '<a  href="/index.php?m=Home&c=Goods&a=goodsInfo&id='+goodsItem.goods_id+'">'+goodsItem.goods_name+goodsItem.spec.key_name+'</a> </div>' +
                    ' <div class="goods-price">商城价：￥'+goodsItem.spec.price+'库存:'+goodsItem.spec.store_count+'</div> </div>';
            $('#goods_name').val(goodsItem.goods_name+goodsItem.spec.key_name);
        }else{
            html =  '<input type="hidden" id="goods_id" name="goods_id" value="'+goodsItem.goods_id+'">' +
                    '<input type="hidden" id="goods_name" name="goods_name" value="'+goodsItem.goods_name+'"> ' +
                    '<div style="float: left;margin: 10px auto;" class="selected-group-goods"><div class="goods-thumb">' +
                    '<img style="width: 162px;height: 162px" src="'+goodsItem.goods_image+'"/></div> <div class="goods-name"> ' +
                    '<a  href="/index.php?m=Home&c=Goods&a=goodsInfo&id='+goodsItem.goods_id+'">'+goodsItem.goods_name+'</a> </div>' +
                    ' <div class="goods-price">商城价：￥'+goodsItem.goods_price+'库存:'+goodsItem.store_count+'</div> </div>';
            $('#goods_name').val(goodsItem.goods_name);
        }
        $('#select_goods_button').attr('data-goods-id',goodsItem.goods_id);
        $('#selected_group_goods').empty().html(html);
        $('.selected-group-goods').show();
        layer.closeAll('iframe');
    }
    function img_call_back(fileurl_tmp)
    {
        $("#imagetext").val(fileurl_tmp);
        $("#img_a").attr('href', fileurl_tmp);
        $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
    }

</script>
</body>
</html>